package com.baomidou.springboot.dto;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

public class QueryCondition <T>{

   
    public QueryWrapper<T> QueryCondition(T t,List< QueryParam> param){
        QueryWrapper <T>queryWrapper = new QueryWrapper<T>();
        if(param==null)return queryWrapper;
        for(QueryParam  q : param){
            String column=q.getKey();
            String val=q.getValue();
            String opration=q.getOperation();
            String orAnd=q.getOrAnd(); 
           if(opration.equals("eq")){
                if(orAnd.equals("and")){
                    // 嵌套and
                    queryWrapper.and(wrapper -> wrapper.eq(column, val));
                    
                }
              
                else if(orAnd.equals("or")){
                    queryWrapper.or(wrapper -> wrapper.eq(column, val));
                }else{
                    queryWrapper.eq(column, val);
                }
           }
        }
        return queryWrapper;

    }

}
